(function($) {
    appcan.button("#nav-left", "btn-act",
    function() {
        appcan.window.close(-1);
        appcan.window.open({
            name: 'index',
            data: 'index.html'
        });
    });
    appcan.button("#nav-right", "btn-act",
    function() {});
    appcan.button("#register", "btn-act",
    function() {
        appcan.window.close(-1);
        appcan.window.open({
            name: 'register',
            data: 'register.html'
        });
    });
    appcan.ready(function() {
        $.scrollbox($("body")).on("releaseToReload",
        function() { //After Release or call reload function,we reset the bounce
            $("#ScrollContent").trigger("reload", this);
        }).on("onReloading",
        function(a) { //if onreloading status, drag will trigger this event
        }).on("dragToReload",
        function() { //drag over 30% of bounce height,will trigger this event
        }).on("draging",
        function(status) { //on draging, this event will be triggered.
        }).on("release",
        function() { //on draging, this event will be triggered.
        }).on("scrollbottom",
        function() { //on scroll bottom,this event will be triggered.you should get data from server
            $("#ScrollContent").trigger("more", this);
        }).hide();
    })

	        appcan.button("#submit", "ani-act", function() {
            $("form").submit();
        })

        $("form").on('submit', function() {
            var username = $("#username").val();
            var password = $("#password").val();
            if (username == "" || password == "") {
                appcan.window.alert({
                    title : "提醒",
                    content : "请输入用户名和密码",
                    buttons : '确定',
                    callback : function(err, data, dataType, optId) {
                        console.log(err, data, dataType, optId);
                    }
                });
            }
            else {
                appcan.request.postForm($("form"), function() {
                    appcan.window.alert({
                    title : "提醒",
                    content : "您已经成功登录",
                    buttons : '确定',
                    callback : function() {
                        // console.log(err, data, dataType, optId);
                        appcan.locStorage.setVal("islog", true); // true 为已登录，false 为未登录
                        appcan.locStorage.setVal("username", username);
                        // appcan.locStorage.setVal("yemian", "login"); //保存页面
                        if (appcan.locStorage.getVal("yemian") == "index") {
                            appcan.window.close(-1);
                            appcan.window.open({
                                name: 'index',
                                data: 'index.html'
                            });
                        }
                        else if (appcan.locStorage.getVal("yemian") == "detail") {
                            appcan.window.close(-1);
                            appcan.window.open({
                                name: 'detail',
                                data: 'detail.html'
                            });
                        }
                    }
                });
            }, function(err) {

            });
            }
            return false;
        });
})($);